<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#assign css>

<link rel="stylesheet" href="/assets/vendor/layui-v2.3.0/css/layui.css">
</#assign>
<#assign js>
	<script src="/assets/vendor/layui-v2.3.0/layui.js"></script>
<script>

    $(function () {
        //$("#imgs").val("");
    })
    layui.use('upload', function() {
        var $ = layui.jquery
                , upload = layui.upload;

        upload.render({
            elem: '#test2'
            ,url: '/upload/uploadImg'
            ,multiple: true
            ,before: function(obj){

                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo2').append('<img style="width: 200px;height:400px;" src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                });
            }
            ,done: function(res){
                //上传完毕
                //如果上传失败
                if (res.code != 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                layer.msg('上传成功');
                if($("#imgs").val()!=''){
                    $("#imgs").val($("#imgs").val()+","+res.data)
                }else{
                    $("#imgs").val(res.data);
                }

            }
        });

    });
    $('.form-edit').bootstrapValidator({
        message: '请输入有效值',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        }
    });


    $(".btn-submit").click(function () {
		// 校验表单合法
		var bootstrapValidator = $(".form-edit").data('bootstrapValidator');
		bootstrapValidator.validate();

        if($("#imgs").val()==''){
            layer.msg("请上传图片！");
            return;
        }
		if(bootstrapValidator.isValid()){
			$.ajax({
				type: "POST",
				dataType: "json",
				url: "/bootstrapimg/edit",
				data: $(".form-edit").serialize(),
				success: function(res){
				    if(res.code=='0'){
                        layer.msg(res.message, {time: 2000
                        }, function(){
                            location.href="/bootstrapimg/index";
                        });
                    }else{
                        layer.msg(res.message);
                    }
				},
                error:function(){
                    layer.msg("shibai ");
                }
			});
		}else{
			return false;
		}

    });


</script>
</#assign>
<@layout title="引导页图片设置" active="bootstrapimg">
<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        引导页图片设置
        <small>编辑</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
        <li class="active"><i class="fa fa-edit"></i> 引导页图片设置</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <!-- Default box -->
            <div class="box  box-primary">
                <form class="form-horizontal form-edit" method="post" action="/bootstrapimg/edit">
                    <div class="box-body">
                        <input type="hidden" id="id" name="id" value="${bootstrapImg.id!}">
                        <input type="hidden" id="isAdd" name="isAdd" value="${isAdd?string('true','false')}">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">图片类型：</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="type" id="type" required disabled>
                                    <option value="">请选择图片类型</option>
                                    <option value="0" <#if bootstrapImg.type??&&bootstrapImg.type==0 >selected</#if>>启动页</option>
                                    <option value="1" <#if bootstrapImg.type??&&bootstrapImg.type==1 >selected</#if>>引导页</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">上传图片：</label>
                            <div class="col-sm-10">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" id="test2">多图片上传</button>
                                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                        预览图：
                                        <div class="layui-upload-list" id="demo2"></div>
                                    </blockquote>
                                </div>
                                <input type="hidden" id="imgs" name="imgUrl">
                            </div>


                        </div>
                    </div>
                    <div class="box-footer">
                        <button type="button" class="btn btn-default btn-back">返回</button>
                        <button type="button" class="btn btn-primary pull-right btn-submit">提交</button>
                    </div>
                </form>
            </div>
            <!-- /.box -->
        </div>
    </div>
</section>
<!-- /.content -->
</@layout>